package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.beans.AdminInfo;
import com.dao.LoginDao;
import com.util.MD5Utils;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	private LoginDao logindao = new LoginDao();
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String adminName = request.getParameter("adminName");
		String password = request.getParameter("password");
		String passwordencryption=MD5Utils.stringToMD5(password);
		AdminInfo admin = logindao.getAdmininfo(passwordencryption,adminName);
		request.getSession().setAttribute("session_admin", admin);
		if(admin==null) {
			response.getWriter().print("0");
		}else {
			if(admin.getRoleid()==null) {
				response.getWriter().print("3");
			}else {
				if(admin.getState()==2) {
					response.getWriter().print("2");
				}else {
					response.getWriter().print("1");
				}
			}
			
		}
	}

}
